package com.jackie.tongzhuang.Classes;

import android.util.Log;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Calendar;

public class BaseClass {
    public static String getDate(){
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1; // 月份是从0开始的，所以要加1
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return year+"-"+NumTo2(month)+"-"+NumTo2(day);
    }

    public static String getNextFenQiData(int i){
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + (i+1); // 月份是从0开始的，所以要加1
        return year+"-"+NumTo2(month)+"-01";
    }

    public static String getDate(Calendar c){
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1; // 月份是从0开始的，所以要加1
        int day = c.get(Calendar.DAY_OF_MONTH);
        return year+"-"+NumTo2(month)+"-01";
    }

    public static DecimalFormat getDecimal(int d) {
        String format = "";
        for(int i = 0;i<d;i++){
            format += "0";
        }
        DecimalFormat df = new DecimalFormat("0."+format);
        df.setRoundingMode(RoundingMode.HALF_UP);
        return df;
    }

    public static double getDecimal(int i,double d){
        return Double.valueOf(getDecimal(i).format(d));
    }
    public static String getDecimalToStr(int i,double d){
        return getDecimal(i).format(BaseClass.getDecimal(i,d));
    }

    public static String NumTo2(int num){
        if(num >=10){
            return String.valueOf(num);
        }else{
            return "0"+num;
        }
    }
}
